import qiniu


access_key = "W0oGRaBkAhrcppAbz6Nc8-q5EcXfL5vLRashY4SI"
secret_key = "tsYCBckepW4CqW0uHb9RdfDMXRDOTEpYecJAMItL"
bucket_name = "information22"


def push(data):
    q = qiniu.Auth(access_key, secret_key)
    token = q.upload_token(bucket_name)
    if not data:
        raise AttributeError("图片数据为空")
    ret, info = qiniu.put_data(token, None, data)
    if info.status_code == 200:
        pass
    else:
        # 抛出异常
        raise AttributeError("上传图片到七牛云失败")
    return ret["key"]


if __name__ == '__main__':
    path = input('请上传文件(路径):')
    with open(path, 'rb') as f:
        print(push(f.read()))
